﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Seagull.Model.Alerts
{
    public class NoDataAlert : Alert
    {
        private readonly byte[] _channels;
        private readonly DateTime _lastTime;

        public NoDataAlert(IEnumerable<byte> channels, DateTime lastTime)
        {
            _channels = channels.ToArray();
            _lastTime = lastTime;
        }

        public override string AlertContent
        {
            get
            {
                return ChannelsString + "无数据";
            }
        }

        public override string AlertDetail
        {
            get
            {
                return string.Format("{0}无数据！最后一次数据采集时间：{1}",
                    ChannelsString,
                    _lastTime == DateTime.MinValue ? "从未" : _lastTime.ToString("yyyy/MM/dd HH:mm:ss"));
            }
        }

        private string ChannelsString
        {
            get { return string.Join(",", _channels.Select(Channel.GetChannelName)); }
        }
    }
}